
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<span style="font-size:18px;">
<html>
<head>
    <title>登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="statusInformation/css/bootstrap.min.css">
    <link rel="stylesheet" href="statusInformation/css/logstyle.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
    <script type="text/javascript" src="statusInformation/js/jquery.min.js"></script>

</head>


<body>

<div class="form-bg" style=" background-image: url(statusInformation/img/logbks.png);
width: 100%; height: 100%; background-size:cover;">
    <div class="container">
        <div class="row">
            <div class="col-md-offset-3 col-md-6">
                <form class="form-horizontal">
                    <span class="heading">学生学籍信息管理系统</span>

                    <div class="text-left" style="margin-left: 50px;">
                        <span id="uname" style="font-size:10px; color: red; text-align: left;">&nbsp;</span>
                    </div>
                    <div class="form-group">
                        <input id="user_name" type="text" class="form-control" id="inputEmail3" placeholder="请输入用户名">
                        <i class="fa fa-user"></i>
                    </div>

                    <div class="text-left" style="margin-left: 50px;">
                        <span id="upawd" style="font-size:10px; color: red;">&nbsp;</span>

                    </div>

                    <div class="form-group help">
                        <input id="user_password" type="password" class="form-control" id="inputPassword3" placeholder="请输入密码">
                        <i class="fa fa-lock"></i>
                    </div>
                    <div class="form-group">
                        <div class="main-checkbox">
                            <input type="checkbox" value="None" id="checkbox1" name="check"/>
                            <label for="checkbox1"></label>
                        </div>
                        <span class="text">记住我</span>
                        <button type="button" class="btn btn-default" onclick="initDate()">登录</button>
                    </div>

                </form>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    function initDate(){
        var uname = $("#user_name").val();
        var upawd = $("#user_password").val();

        if($.isEmptyObject(uname)){
            $("#uname").text("请输入用户名");
            return;
        }else {
            $("#uname").text(" ");
        }
        if($.isEmptyObject(upawd)){
            $("#upawd").text("请输入密码");
            return;
        }else {
            $("#upawd").text(" ");
        }

        var postUrl = "${pageContext.request.contextPath}/userLogin";
        var urlad = "${pageContext.request.contextPath}/admin";
        var urlth = "${pageContext.request.contextPath}/teacher";
        var urlus = "${pageContext.request.contextPath}/user";

        var str = {
            "userLoginName": uname,
            "userLoginPwd": upawd
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    if (data.msg == "密码错误"){
                        $("#upawd").text("密码错误");
                    }else {
                        $("#uname").text(data.msg);
                    }
                }else {
                    if(data.result.userLevel === "0"){
                        location.href = urlad;
                    }else if (data.result.userLevel === "1") {
                        location.href = urlth;
                    }else if (data.result.userLevel === "2") {
                        location.href = urlus;
                    }
                    sessionStorage.setItem("user",JSON.stringify(data));
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }


</script>

</body>
</html>
</span>